package do

import (
	"context"
	"micro.hotel.server/common"
	"micro.hotel.server/database"
	"micro.hotel.server/models"
)

func AreaListMap(ctx context.Context) (map[int32]string, error) {
	areas := make([]*models.AreaList, 0)

	eg := database.GetDB()
	if eg == nil {
		return nil, common.DBNil
	}

	err := eg.Select("id, parent_id, level, name").Table("vs_area").Find(areas)
	if err != nil {
		return nil, common.DBErr
	}

	areaMap := make(map[int32]string)
	for _, v := range areas {
		areaMap[v.ID] = v.Name
	}
	return areaMap, nil
}

func CircleMap(ctx context.Context) (map[int32]string, error) {
	circles := make([]*models.BusinessCircle, 0)

	eg := database.GetDB()
	if eg == nil {
		return nil, common.DBNil
	}

	err := eg.Select("id, circle_name").Table("vs_business_circle").Find(circles)
	if err != nil {
		return nil, err
	}

	circleMap := make(map[int32]string)
	for _, v := range circles {
		circleMap[v.Id] = v.CircleName
	}
	return circleMap, nil
}
